package com.epro.dx.adapter;

import java.util.ArrayList;

import com.epro.dx.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CountryListSearchAdapter extends BaseAdapter {
	
	private Context mCountext;
	private ArrayList<String> countryList;

	public CountryListSearchAdapter(Context mCountext,ArrayList<String> countryList){
		this.mCountext = mCountext;
		this.countryList = countryList;
		
	}

	@Override
	public int getCount() {
		// 数据条目数量
		if(countryList!=null)
			return countryList.size();
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// 对应位置的条目对象
		if(countryList.size()!=0)
			return countryList.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView == null){
			holder  = new ViewHolder();
			//没有缓存
			convertView = View.inflate(mCountext, R.layout.row_view, null);
			holder.text_title = (TextView) convertView.findViewById(R.id.row_title);
			//设置标记用于缓存复用
			convertView.setTag(holder);
		}else{
			//有缓存，复用缓存
			holder = (ViewHolder) convertView.getTag();
		}
		//设置数据显示
		holder.text_title.setText(countryList.get(position));
		return convertView;
	}
	
	class ViewHolder{
		TextView text_title;
	}

}
